package com.grm.strategy.factory;

import com.grm.strategy.handler.Handler;
import org.apache.commons.lang3.ObjectUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * 工厂 -> 生产策略
 *
 * @author gaorimao
 * @date 2022/02/22
 */
public class Factory {
    private static Map<String, Handler> strategyMap = new HashMap<>();

    public static Handler getInvokeStrategy(String type) {
        return strategyMap.get(type);
    }

    public static void register(String name, Handler handler) {
        if (ObjectUtils.isEmpty(name) && handler == null) {
            return;
        }
        strategyMap.put(name, handler);
    }
}
